      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ol class="breadcrumb">
            <li><a href="<?=site_url()?>/stock/index">库存商品管理</a></li>
            <li class="active">库存商品列表</li>
          </ol>
          <div class="row margin-bottom-10">
            <div class="col-md-12">
              <ul class="nav nav-pills">
                <li class="active"><a href="<?=site_url()?>/stock/add">添加库存商品</a></li>
                 <li class="active"><a href="<?=site_url()?>/stock/records">库存购买记录</a></li>
              </ul>          
            </div>
             </div> 
           <div class="row margin-bottom-5">
            <div class="col-md-12">
            		<input type="text" id="name" name="name" value="">
            		<button class="btn btn-primary" id="submit_btn">搜索</button>
            </div>
          </div> 
          <div class="row">
            <div class="col-md-12">
              <div class="table-responsive">
                <h4 class="margin-bottom-15">库存商品列表</h4>
                <table class="table table-striped table-hover table-bordered">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>库存商品名称</th>
                      <th>库存量</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                  	<?php foreach ($stocks as $item):?>
                  	<tr>
                      <td><?php echo $item['id'];?></td>
                      <td><?php echo $item['name'];?></td>
                      <td><?php echo $item['stock'];?></td>
                      <td><a href="#" class="btn btn-link del" data-id="<?php echo $item['id'];?>" >删除</a></td>
                    </tr>
                     <?php endforeach;?>
                  </tbody>
                </table>
              </div>
              <!--<ul class="pagination pull-right">
                <li class="disabled"><a href="#">&laquo;</a></li>
                <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">2 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">3 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">4 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">5 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">&raquo;</a></li>
              </ul>  -->
            </div>
          </div>
          <div class="pagination">
            <?php echo $links ;?>
          </div>
        </div>
      </div>
    <script>
	$(document).ready(function() {
		$("#submit_btn").click(function() {
			var name = $("#name").val();
			if(name==""||name==null){
				name="empty";
			}
			var url = "<?php echo site_url('stock/index')?>";
			window.location.href=url+"/name/"+name;
		});
		$("#name").keydown(function(e) {
			if(e.keyCode == 13) {
				var name = $("#name").val();
				if(name==""||name==null){
					name="empty";
				}
				var url = "<?php echo site_url('stock/index')?>";
				window.location.href=url+"/name/"+name;
			}
		});
		$(".del").click(function() {
			if(confirm("确定要删除该数据吗？"))
			{
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('stock/delete')?>',
				type : "post",
				async : true,
				data : {
					'id' : id
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
	}); 
</script>